using System;
using System.Data;
using System.Collections.Generic;
using System.Collections;
using log4net;
using WEB.BLL.Entities;
using WEB.Exceptions;
namespace WEB.BLL.Services
{
	#region StudentService

	/// <summary>
	/// DesktopService object for Ibatis mapped table 'Desktop'.
	/// </summary>
	public class StudentService : IStudentService
	{
		private static readonly ILog log = LogManager.GetLogger(typeof(StudentService).Name);
	  	private static volatile StudentService _StudentService = null;
        public static StudentService GetInstance()
        {
            if (_StudentService == null)
            {
                lock (typeof( StudentService))
                {
                    if (_StudentService == null) // double-check
                        _StudentService = new StudentService();
                }
            }
            return _StudentService;
        }
		public StudentService()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public IList<StudentEntity> Find(StudentEntity obj)
        {
            try
            {
                IList<StudentEntity> resul = ExecuteQueryForList<StudentEntity>("StudentSearch", obj);
                return resul;
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }

        public IList<StudentEntity> LoadHaveProject(StudentEntity obj)
        {
            try
            {
                IList<StudentEntity> resul = ExecuteQueryForList<StudentEntity>("StudentLoadHaveProject", obj);
                return resul;
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }

        public IList<StudentEntity> LoadByProject(StudentEntity obj)
        {
            try
            {
                IList<StudentEntity> resul = ExecuteQueryForList<StudentEntity>("StudentLoadByProject", obj);
                return resul;
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }

        public int DeleteProject(StudentEntity objE)
        {
            try
            {
                ExecuteDelete("StudentDeleteProject", objE);
                return 1;
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }

        public int UpdateProject(StudentEntity objE)
        {
            try
            {
                ExecuteDelete("StudentUpdateProject", objE);
                return 1;
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }

        public int DeleteAll()
        {
            try
            {
                ExecuteDelete("StudentDeleteAll", null);
                return 1;
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }

        public IList<StudentEntity> LoadCv(string query, bool haveCv, int start, int limit, out int Total)
        {
            Total = 0;
            try
            {
                StudentEntity obj = new StudentEntity
                {
                    Keyword = query,
                    HaveCv = haveCv,
                    Start = start,
                    EndNum = limit,
                    TotalRow = Total
                };
                IList<StudentEntity> resul = ExecuteQueryForList<StudentEntity>("StudentLoadCv", obj);
                Total = obj.TotalRow;
                return resul;
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }
    }
    #endregion
}
